/*
 * TrackerSD.cc
 *
 *  Created on: 14.04.2011
 *      Author: ed
 */

#include "TrackerSD.hh"
#include "globals.hh"
#include "G4VProcess.hh"
TrackerSD::TrackerSD(G4String name) : G4VSensitiveDetector(name)
{
	file = new TFile("~/tree3.root","recreate");
	tree = new TTree("aTree","Event tree");
	tree->Branch("numOfEvt",&evt.ppe,"numOfEvt/I");
	tree->Branch("theta",&evt.theta,"Theta/D");
}

TrackerSD::~TrackerSD()
{

	tree->Write();
	delete tree;
	file->Close();
}
bool TrackerSD::ProcessHits(G4Step*aStep,G4TouchableHistory*)
{
	G4ThreeVector v = aStep->GetPostStepPoint()->GetMomentumDirection();
	v.setX(-v.getX());
	G4ThreeVector ex(1,0,0);

	G4double cos = v.dot(ex)/(v.mag()*ex.mag());
	evt.theta = std::acos(cos);
	G4cout<<evt.theta<<G4endl;
	tree->Fill();
	return true;
}
void TrackerSD::Initialize(G4HCofThisEvent*)
{
	count = 0;
}
void TrackerSD::EndOfEvent(G4HCofThisEvent*)
{
}
